<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>sessionStorate</title>
</head>

<body>
    <h3>测试html localStorate</h3>
    <button onclick="add()">添加一个数据</button>
    <button onclick="get()">读取一个数据</button>
    <button onclick="deleteOne()">删除一个数据</button>
    <button onclick="clearAll()">清空数据</button>
</body>


<script>
    function add() {

        // window.sessionStorage.setItem("msg", "张三")
        sessionStorage.setItem("msg", "张三")
        sessionStorage.setItem("msg2", "李四")
        let p = { id: "1", name: "aaa" }
        sessionStorage.setItem("msgObj", JSON.stringify(p))
    }

    function get() {
        console.log('msg', sessionStorage.getItem("msg"))
        console.log('msg2', sessionStorage.getItem("msg2"))
        console.log('msgObj', JSON.parse(sessionStorage.getItem("msgObj")))
    }
    function deleteOne() {
        sessionStorage.removeItem("msg")
    }
    function clearAll() {
        console.log('@@@@clear')
        sessionStorage.clear()
    }

</script>

</html>